
//liuweibo add start 20120326
package com.android.matmanual;


import android.app.Activity;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.TextView;


public class KeypadTest extends BaseActivity 
{
	
	TextView mVolumeUpButton;
	TextView mVolumeDownButton;
	TextView mBackButton;
	TextView mMuteButton;
	TextView mHomeButton;

	boolean mFinishVolumeUpFlag = false;
	boolean mFinishVolumeDownFlag = false;

	boolean mFinishBackFlag = false;

	boolean mFinishMuteFlag = false;
	boolean mFinishAllFlag = false;
	boolean mHomeFlag = false;
	WakeLock mWakeLock;
	public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);//MTK����home����
		setContentView(R.layout.keypad_test);
		setTitle(R.string.keypad_title);
	    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); 
		mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "XYTEST"); 
		mWakeLock.acquire(); 		
		
		mVolumeUpButton = (TextView) findViewById(R.id.volume_up_button);		
		mVolumeDownButton = (TextView) findViewById(R.id.volume_down_button);		

		
		mBackButton = (TextView) findViewById(R.id.back_button);			
		
		mMuteButton = (TextView) findViewById(R.id.mute_button);	
		
		mHomeButton = (TextView)findViewById(R.id.home_button);	
		

	}
	 @Override
	 public boolean onKeyUp(int keyCode, KeyEvent event) {	 
		if(keyCode == KeyEvent.KEYCODE_BACK)
		{
		 	mBackButton.setTextColor(0xff00ff00);
		 	mFinishBackFlag = true;
		}
		else if(keyCode == KeyEvent.KEYCODE_HOME)
		{
			mHomeButton.setTextColor(0xff00ff00);
			mHomeFlag = true;
					
		}
		 	return true;
	 } 	
		
		
	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {	 	
		{
			    Log.v("leiyonghui", "keyCode:"+keyCode);
			 	if(keyCode == KeyEvent.KEYCODE_VOLUME_UP)
			 	{
			 		mVolumeUpButton.setTextColor(0xff00ff00);
			 		mFinishVolumeUpFlag = true;
					
			 	}
			 	else if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
			 	{
			 		mVolumeDownButton.setTextColor(0xff00ff00);
			 		mFinishVolumeDownFlag = true;
					
			 	}	
			 	else if(keyCode == KeyEvent.KEYCODE_BACK)
			 	{
			 		mBackButton.setTextColor(0xff00ff00);
			 		mFinishBackFlag = true;
					
			 	}
			 	else if(keyCode == KeyEvent.KEYCODE_MENU)
			 	{
			 		mMuteButton.setTextColor(0xff00ff00);
			 		mFinishMuteFlag = true;
					
			 	}
			 	else if(keyCode == KeyEvent.KEYCODE_HOME)
			 	{
			 		mHomeButton.setTextColor(0xff00ff00);
			 		mHomeFlag = true;
					
			 	}
				
			 	if(mFinishVolumeUpFlag==true
			 	   &&mFinishVolumeDownFlag==true
			 	   &&mFinishBackFlag==true
			 	   &&mFinishMuteFlag==true
			 	   &&mHomeFlag == true)
			 	{
			 		mFinishAllFlag = true;
			 		//finish();
			 	}
		}	 	
	 	return true;
 	}
	 
		@Override
		protected void onDestroy() {
			// TODO Auto-generated method stub
			if(mWakeLock!=null)
			{
				mWakeLock.release(); 
				mWakeLock = null;
			}
			super.onDestroy();
		}
		
		
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
        finish();
		super.onStop();
	}
	
	private boolean catchHomeKey = false;
	
	
	@Override
	public void onAttachedToWindow() 
	{
		
		this.getWindow().setType(WindowManager.LayoutParams.FLAG_HOMEKEY_DISPATCHED);
		
		// TODO Auto-generated method stub
		super.onAttachedToWindow();
	}

	

	
}
//liuweibo end
		 